﻿
using Maticsoft.BLL;
using Maticsoft.Model;
using System;
using System.Collections.Specialized;
using System.IO;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class WebPage_SheZhi_Jiben : SystemBBasePage
{
    private NameValueCollection _system = null;
    public string check1 = "";
    public string check2 = "";
    public string check3 = "";
    public string check4 = "";

    public string strcheck3 = "";
    public string strcheck4 = "";
    public SystemConfig sysmodel = new SystemConfig();
    private Maticsoft.BLL.System systems = new Maticsoft.BLL.System();


    private void getSystem()
    {
        foreach (Maticsoft.Model.System system in this.systems.GetModelList("Id=1"))
        {
            this._system = this.sysmodel.GetSystem();
            if (this._system["moretuan"] == "0")
            {
                this.check1 = "checked=checked";
                this.check2 = "";
            }
            else if (this._system["moretuan"] == "1")
            {
                this.check1 = "";
                this.check2 = "checked=checked";
            }
            if (this._system["shanhu"] == "0")
            {
                this.check3 = "checked=checked";
                this.check4 = "";
            }
            else if (this._system["shanhu"] == "1")
            {
                this.check3 = "";
                this.check4 = "checked=checked";
            }
            ListItem item = new ListItem();
            item.Text = "是";
            item.Value = "1";
            ListItem item2 = new ListItem();
            item2.Text = "否";
            item2.Value = "0";
            if (system.Needmoretuan == 1)
            {
                item.Selected = true;
            }
            else
            {
                item2.Selected = true;
            }
            this.ddlmore.Items.Add(item);
            this.ddlmore.Items.Add(item2);
            this.ddlmore.DataBind();
            this.sitename.Value = system.sitename;
            this.sitetitle.Value = system.sitetitle;
            this.abbreviation.Value = system.abbreviation;
            this.couponname.Value = system.Couponname;
            this.currency.Value = system.Currency;
            this.currencyname.Value = system.Currencyname;
            this.invitecredit.Value = Convert.ToInt32(system.Invitecredit).ToString();
            this.sideteam.Value = system.Sideteam.ToString();
            this.headlogodef.Value = system.headlogo;
            this.footlogodef.Value = system.Footlogo;
            this.printlogodef.Value = system.Printlogo;
            this.emaillogodef.Value = system.Emaillogo;
            this.conduser.Value = system.conduser.ToString();
            this.partnerdown.Value = system.partnerdown.ToString();
            this.kefuqq.Value = system.kefuqq;
            this.kefumsn.Value = system.Kefumsn;
            this.icp.Value = system.Icp;
            this.statcode.Value = system.Statcode;
            this.sinajiwai.Value = system.Sinablog;
            this.tencentjiwai.Value = system.Qqblog;
            this.title.Value = system.Title;
            this.keyword.Value = system.KeyWord;
            this.description.Value = system.Description;
            this.jobtime.Value = system.Jobtime;
        }
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        this.HeaderControl1.Select = "shezhi";
        if (!base.IsPostBack)
        {
            this.getSystem();
        }
    }

    protected void save_Click(object sender, EventArgs e)
    {
        string fileName;
        int num;
        string str6;
        string str7;
        Exception exception;
        string str9;
        Maticsoft.Model.System model = new Maticsoft.Model.System();
        this._system = new NameValueCollection();
        model = this.systems.GetModel(1);
        model.sitename = this.sitename.Value;
        model.sitetitle = this.sitetitle.Value;
        model.abbreviation = this.abbreviation.Value;
        model.Couponname = this.couponname.Value;
        model.Currency = this.currency.Value;
        model.Currencyname = this.currencyname.Value;
        model.Invitecredit = Convert.ToDecimal(this.invitecredit.Value);
        model.Sideteam = Convert.ToInt32(this.sideteam.Value);
        model.Title = this.title.Value;
        model.KeyWord = this.keyword.Value;
        model.Description = this.description.Value;
        model.Needmoretuan = int.Parse(this.ddlmore.SelectedItem.Value);
        string str = base.Request["more"];
        string str2 = base.Request["shanhu"];
        this._system.Add("moretuan", base.Request["more"]);
        this._system.Add("shanhu", base.Request["shanhu"]);
        this.sysmodel.CreateSystemByNameCollection(this._system);
        Random random = new Random();
        string path = "/upfile/logo/";
        if (this.headlogo.FileName != "")
        {
            if (this.headlogo.PostedFile.ContentLength > 0x7d000)
            {
                this.SetError("请上传 512KB 以内的图片!");
                return;
            }
            fileName = this.headlogo.FileName;
            string str5 = "";
            if (this.headlogo.FileName != "")
            {
                num = fileName.LastIndexOf(".");
                str6 = fileName.Substring(num);
                str5 = DateTime.Now.Ticks.ToString() + random.Next() + str6;
            }
            try
            {
                if (fileName != "")
                {
                    str7 = base.Server.MapPath(path);
                    if (!Directory.Exists(str7))
                    {
                        Directory.CreateDirectory(str7);
                    }
                    this.headlogo.PostedFile.SaveAs(str7 + str5);
                }
            }
            catch (Exception exception1)
            {
                exception = exception1;
                base.Response.Write(exception);
            }
            model.headlogo = path + str5;
        }
        if (this.footlogo.FileName != "")
        {
            if (this.footlogo.PostedFile.ContentLength > 0x7d000)
            {
                this.SetError("请上传 512KB 以内的个人肖像图片!");
                return;
            }
            fileName = this.footlogo.FileName;
            string str8 = "";
            if (this.footlogo.FileName != "")
            {
                num = fileName.LastIndexOf(".");
                str6 = fileName.Substring(num);
                str8 = DateTime.Now.Ticks.ToString() + random.Next() + str6;
            }
            try
            {
                if (fileName != "")
                {
                    str7 = base.Server.MapPath(path);
                    if (!Directory.Exists(str7))
                    {
                        Directory.CreateDirectory(str7);
                    }
                    this.footlogo.PostedFile.SaveAs(str7 + str8);
                }
            }
            catch (Exception exception2)
            {
                exception = exception2;
                base.Response.Write(exception);
            }
            model.Footlogo = path + str8;
        }
        if (this.printlogo.FileName != "")
        {
            if (this.printlogo.PostedFile.ContentLength > 0x7d000)
            {
                this.SetError("请上传 512KB 以内的图片!");
                return;
            }
            fileName = this.printlogo.FileName;
            str9 = "";
            if (this.printlogo.FileName != "")
            {
                num = fileName.LastIndexOf(".");
                str6 = fileName.Substring(num);
                str9 = DateTime.Now.Ticks.ToString() + random.Next() + str6;
            }
            try
            {
                if (fileName != "")
                {
                    str7 = base.Server.MapPath(path);
                    if (!Directory.Exists(str7))
                    {
                        Directory.CreateDirectory(str7);
                    }
                    this.printlogo.PostedFile.SaveAs(str7 + str9);
                }
            }
            catch (Exception exception3)
            {
                exception = exception3;
                base.Response.Write(exception);
            }
            model.Printlogo = path + str9;
        }
        if (this.emaillogo.FileName != "")
        {
            if (this.emaillogo.PostedFile.ContentLength > 0x7d000)
            {
                this.SetError("请上传 512KB 以内的图片!");
                return;
            }
            fileName = this.emaillogo.FileName;
            str9 = "";
            if (this.emaillogo.FileName != "")
            {
                num = fileName.LastIndexOf(".");
                str6 = fileName.Substring(num);
                str9 = DateTime.Now.Ticks.ToString() + random.Next() + str6;
            }
            try
            {
                if (fileName != "")
                {
                    str7 = base.Server.MapPath(path);
                    if (!Directory.Exists(str7))
                    {
                        Directory.CreateDirectory(str7);
                    }
                    this.emaillogo.PostedFile.SaveAs(str7 + str9);
                }
            }
            catch (Exception exception4)
            {
                exception = exception4;
                base.Response.Write(exception);
            }
            model.Emaillogo = path + str9;
        }
        model.Jobtime = this.jobtime.Value;
        model.conduser = int.Parse(this.conduser.Value);
        model.partnerdown = new int?(int.Parse(this.partnerdown.Value));
        model.kefuqq = this.kefuqq.Value;
        model.Kefumsn = this.kefumsn.Value;
        model.Icp = this.icp.Value;
        model.Statcode = this.statcode.Value;
        model.Sinablog = this.sinajiwai.Value;
        model.Qqblog = this.tencentjiwai.Value;
        this.systems.Update(model);
        base.SetSuccess("设置成功");
        base.Response.Redirect("~/webpage/shezhi_jiben.aspx");
        base.Response.End();
    }
}


